//package cn.qidd.keep.domain.web;
//
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.MethodParameter;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.support.WebDataBinderFactory;
//import org.springframework.web.context.request.NativeWebRequest;
//import org.springframework.web.method.support.HandlerMethodArgumentResolver;
//import org.springframework.web.method.support.ModelAndViewContainer;
//import org.springframework.web.multipart.support.MissingServletRequestPartException;
//
///**
// * Created by sunyanping on 2018/9/17
// */
//public class TokenUserArgumentResolver implements HandlerMethodArgumentResolver {
//
//    @Autowired
//    private RedisTemplate<String, Object> redisTemplate;
//
//    @Override
//    public boolean supportsParameter(MethodParameter parameter) {
//        return parameter.hasParameterAnnotation(TokenUser.class);
//    }
//
//    @Override
//    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
//                                  NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
//        TokenUser parameterAnnotation = parameter.getParameterAnnotation(TokenUser.class);
//        if (parameterAnnotation != null) {
//            String token = webRequest.getHeader("X-Header-Token");
//            if (StringUtils.isBlank(token)) throw new MissingServletRequestPartException("X-Header-Token");
//            return redisTemplate.opsForValue().get(token);
//        }
//        return null;
//
//    }
//}
